package com.jiandaoshou.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jiandaoshou.R;
import com.jiandaoshou.entry.DingDanDetailEntry;
import com.jiandaoshou.entry.DingDanEntry;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/9/27.
 */

public class ExPanAdapter extends BaseExpandableListAdapter {
    private List<String> parents;
    private Map<String, List<DingDanDetailEntry>> childs;
    public Context context;

    public ExPanAdapter(Context context, List<String> parents, Map<String, List<DingDanDetailEntry>> childs) {
        this.parents = parents;
        this.childs = childs;
        this.context = context;
    }

    @Override
    public int getGroupCount() {
        return parents.size();
    }

    @Override
    public int getChildrenCount(int i) {
        String key = parents.get(i);
        int size = childs.get(key).size();
        return size;
    }

    @Override
    public Object getGroup(int i) {
        return parents.get(i);
    }

    @Override
    public Object getChild(int i, int i1) {
        return childs.get(parents.get(i)).get(i1);
    }

    @Override
    public long getGroupId(int i) {
        return i;
    }

    @Override
    public long getChildId(int i, int i1) {
        return i1;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_parent, null);
        }
        LinearLayout LinearLay = (LinearLayout) view.findViewById(R.id.lin_data);
        TextView textView = (TextView) view.findViewById(R.id.tv_data);
        textView.setText(parents.get(i));
        return view;
    }

    @Override
    public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_child, null);
        }
        TextView Tv_name = (TextView) view.findViewById(R.id.tv_name);
        TextView Tv_data = (TextView) view.findViewById(R.id.tv_time);
        TextView Tv_privce = (TextView) view.findViewById(R.id.tv_price);
        String key = parents.get(i);
        List<DingDanDetailEntry> entrys = (List<DingDanDetailEntry>) childs.get(key);
        Tv_name.setText(entrys.get(i1).getStrShopName());
        Tv_data.setText(entrys.get(i1).getDtCreateTime());
        Tv_privce.setText(entrys.get(i1).getnOrderAmount()+"元");
        return view;
    }
    @Override
    public boolean isChildSelectable(int i, int i1) {
        return true;
    }
}